package com.example.nophase.base;
import android.content.Intent;
import android.os.Bundle;
import android.view.WindowManager;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import com.example.nophase.LoginActivity;
import com.example.nophase.common.ITokenTimeout;
import com.example.nophase.common.LoginManager;
import com.example.nophase.common.MyActivityManager;
import com.example.nophase.utils.HttpUtils;

public class BaseActivity extends AppCompatActivity implements ITokenTimeout {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        MyActivityManager.addActivity(this);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_SECURE,WindowManager.LayoutParams.FLAG_SECURE);
        HttpUtils.getInstance().setTokenTimeoutListener(this);
        super.onCreate(savedInstanceState);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        MyActivityManager.removeActivity(this);
    }

    @Override
    public void onTimeout() {
        Intent intent = new Intent(this, LoginActivity.class);
        startActivity(intent);
        LoginManager.clearToken(this);

        finish();
    }
}
